package com.sumer.thread;

/**
 * 插队，
 */
public class ThreadJoin implements Runnable{
    @Override
    public void run() {
        for (int i = 0; i < 10; i++) {
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(Thread.currentThread().getName() + "执行join线程..." + i);
        }
    }

    public static void main(String[] args) throws InterruptedException {
        ThreadJoin threadJoin = new ThreadJoin();
        Thread thread = new Thread(threadJoin,"子线程");
        for (int i = 0; i < 100; i++) {
            if (i == 20){
                thread.start();
                thread.join();
            }
            System.out.println(Thread.currentThread().getName() + "执行主线程" + i);
        }
    }
}
